﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="esindusoigusType_v4", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(EsindusoigusTypeV4))]
    public class EsindusoigusTypeV4Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IEsindusoigusTypeV4 clazz;
        
        public EsindusoigusTypeV4Serializer(IEsindusoigusTypeV4 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("tegevus");
            if (clazz.Tegevus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tegevus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Tegevus");
            }
            Writer.WriteEndElement();
            if (clazz.Roll!=null) {
                Writer.WriteStartElement("roll");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Roll))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Liik!=null) {
                Writer.WriteStartElement("liik");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Liik))).ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("kirjeldus");
            if (clazz.Kirjeldus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kirjeldus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Kirjeldus");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="tegevus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>esindusoigusType_v4>tegevus");
                }
                clazz.Tegevus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tegevus")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>esindusoigusType_v4>tegevus", Reader.LocalName);
            }
            if (Reader.LocalName=="roll") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>esindusoigusType_v4>roll");
                }
                clazz.Roll = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("roll")).Value;
            }
            if (Reader.LocalName=="liik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>esindusoigusType_v4>liik");
                }
                clazz.Liik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("liik")).Value;
            }
            if (Reader.LocalName=="kirjeldus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>esindusoigusType_v4>kirjeldus");
                }
                clazz.Kirjeldus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kirjeldus")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>esindusoigusType_v4>kirjeldus", Reader.LocalName);
            }
        }
    }
}
